/**
 * 初始化创建行对象，并指定父对象，父节点，及行高度。如果父对象参数为空，将抛出异常。固定列和数据列的父对象必须同时赋值
 * 其中有一个对象赋值不正确，两个对象将不被赋值。‘
 * 
 * @param {Object} aoParentGrid [必选] 指定行的父对象
 * @param {Object} aelParentFixed [可选] 指定固定列的父节点，必须与数据列父节点同时赋值
 * @param {Object} aelParentData [可选] 指定数据列的父节点，必须与固定列父节点同时赋值
 * @param {Object} aHeight [可选] 指定行高度，如不指定，系统将按照数据列默认行高赋值
 */
var JieRow = function(aoParentGrid, aHeight, aelParentFixed, aelParentData){
		
	if(aoParentGrid == null) throw new Error(sGmsg["ROW_002"]);
	this.oParentGrid = aoParentGrid;
	
	if (aelParentFixed == null || aelParentData == null 
		|| aelParentFixed.nodeType != 1 || aelParentData.nodeType != 1) {
			
		this.elParentFixed = null;
		this.elParentData = null;
	}else{
		this.elParentFixed = aelParentFixed;
		this.elParentData = aelParentData;		
	}
//	alert(Properties.system.ROW_TAG);
	this.elFixedRow = document.createElement(Properties.system.ROW_TAG);
	this.elDataRow = document.createElement(Properties.system.ROW_TAG);
	
	this.iRowHeight = 0;
//	alert(this.iRowHeight);
		
	this.iDataWidth = 0;
	this.iFixedWidth = 0;

	this.cells = new Array();
	
	if(aHeight == null){
		this.setHeight(Properties.grid.row.height);
	}else{
		this.setHeight(aHeight);
	}
}

JieRow.prototype = {
	/**
	 * 添加单元格，将参数指定的单元格添加到本行
	 * @param {Object} aoCell[必选] 被添加的单元格，当该参数为空时，系统将抛出异常
	 */
	appendCell : function(aoCell){
		if(aoCell == null) throw new Error(sGmsg["ROW_003"]);
		//aoCell.setHeight(this.getHeight());
	
		if (aoCell.isFixed) {
			aoCell.appendCell("getFixedRow", this);
		}else{
			aoCell.appendCell("getDataRow", this);			
		}
		this.cells.push(aoCell);

	},
	/**
	 * 向Grid添加行，其父节点指定以本方法参数为主。当本方法参数要求的两个节点有一个为空时，检测对象内部父节点状态，
	 * 如果同样为空时，抛出异常。否则将行节点对象显示出来
	 * 
	 * @param {Object} aelParentFixed 固定列父节点
	 * @param {Object} aelParentData 数据列父节点
	 */
	addRowToGrid : function(aelParentFixed, aelParentData){
		if (aelParentFixed == null || aelParentData == null 
			|| aelParentFixed.nodeType != 1 || aelParentData.nodeType != 1) {

			if (this.elParentFixed == null || this.elParentData == null) {
				throw new Error(sGmsg["ROW_001"]);
			}
		}else{
			this.elParentFixed = aelParentFixed;
			this.elParentData = aelParentData;				
		}
		this.elParentFixed.appendChild(this.elFixedRow);
		this.elParentData.appendChild(this.elDataRow);
	},
	
	insertRowToGrid : function(aelParentFixed, aelParentData){
		var oColumns = this.oParentGrid.columns;
		for(var i=0; i<oColumns.length; i++){
			var sClassName = Properties.system.cellClass[oColumns[i].dateType];
			if(sClassName == null || typeof(sClassName) != "string"){

				throw new Error(sGmsg["ROW_004"]);	
			}
			var oCell = new window[sClassName](oColumns[i], this);
//			oCell.editCell();
			this.appendCell(oCell);
		}
		this.addRowToGrid(aelParentFixed, aelParentData)
	},
	setRowColor : function(asBgColor){
		if(asBgColor){
			for(var i=0; i<this.cells.length; i++){
				this.cells[i].setBgColor(asBgColor);
			}
		}else{
			for(var i=0; i<this.cells.length; i++){
				this.cells[i].setBgColor(this.cells[i].parentCol.dateBgColor);
			}
		}
	},
	
	
	setHeight : function(aHeight){
		this.iRowHeight = Util.getLengthNumber(aHeight);
		this.elFixedRow.style.height = this.getHeight();
		this.elDataRow.style.height = this.getHeight();
		var oCell = null;
//		alert(this.cells);
		for(var i=0; i<this.cells.length; i++){
			oCell = this.cells[i];
			oCell.setHeight(this.iRowHeight);
		}
	},
	getHeight : function(aHeight){
		return this.iRowHeight +"px";
	},
	setFixedWidth : function(aWidth){
		this.iFixedWidth = Util.getLengthNumber(aWidth);
		this.elFixedRow.style.width = this.iFixedWidth+"px";
	},
	setDataWidth : function(aWidth){
		
		this.iDataWidth = Util.getLengthNumber(aWidth);
		this.elDataRow.style.width = this.iDataWidth+"px";
	},
	getFixedRow : function(){
		return this.elFixedRow;
	},
	getDataRow : function(){
		return this.elDataRow;
	}
}
